package com.aixin.project.util;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {
    private static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm");


    //获取当前时间
    public static String simpleDate() {
        return dateformat.format(new Date());
    }

    public static Date strToDate(String date) {
        try {
            return dateformat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static int compareToDays(Date endtime) {

        Date date = new Date();
        if (date.before(endtime)) {

            long intervalMilli = endtime.getTime() - date.getTime();
            return (int) (intervalMilli / (24 * 60 * 60 * 1000));

        } else {
            return -1;
        }

    }

    public static int compareToHours(Date endtime) {

        Date date = new Date();
        long intervalMilli = endtime.getTime() - date.getTime();
        return (int) (intervalMilli / (60 * 60 * 1000));
/*		   if(date.before(endtime)){

			 long intervalMilli = endtime.getTime() - date.getTime();
		     return (int) (intervalMilli / (60 * 60 * 1000));
		
		   }else{
		      return -1;
		   }*/
    }

    public static XMLGregorianCalendar convertToXMLGregorianCalendar(Date date) {

        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        XMLGregorianCalendar gc = null;
        try {
            gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
        }
        return gc;
    }


    public static void main(String[] args) {
//		System.out.println(strToDate("2012-05-08 16:30"));
        System.out.println(-9 / 2);
    }
}
